package pl.register.android.util;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Mateusz Strzelecki
 * @since 2013-04-30
 */
public final class DualMap<K1, K2, V> {

    private final Map<K1, Map<K2, V>> map = new HashMap<K1, Map<K2, V>>();

    public V get(K1 key1, K2 key2) {
        Map<K2, V> subMap = map.get(key1);
        if (subMap != null) {
            return subMap.get(key2);
        } else {
            return null;
        }
    }

    public void put(K1 key1, K2 key2, V value) {
        Map<K2, V> subMap = map.get(key1);
        if (subMap != null) {
            subMap.put(key2, value);
        } else {
            subMap = new HashMap<K2, V>();
            subMap.put(key2, value);
        }
        map.put(key1, subMap);
    }

}